package com.longge;

import java.util.Arrays;

public class FindMiddleIndex {

    public int findMiddleIndex(int[] nums) {

        int sum = Arrays.stream(nums).sum();

        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (sum-nums[i]-count==count){
                return i;
            }
            count+=nums[i];
        }
        return -1;
    }

    public static void main(String[] args) {
        new FindMiddleIndex().findMiddleIndex(new int[]{2,3,-1,8,4});
    }
}
